package cn.tedu.cwfw.feedback.service.impl;


import cn.tedu.cwfw.feedback.mapper.FeedbackMapper;
import cn.tedu.cwfw.feedback.pojo.dto.FeedbackQuery;
import cn.tedu.cwfw.feedback.pojo.dto.SaveFeedbackFrom;
import cn.tedu.cwfw.feedback.pojo.entity.Feedback;
import cn.tedu.cwfw.feedback.pojo.vo.FeedbackVO;
import cn.tedu.cwfw.feedback.service.FeedbackService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Slf4j
@Service
public class FeedbackServiceImpl implements FeedbackService {
    @Autowired
    private FeedbackMapper feedbackMapper;

    /**
     * 保存举报信息
     * @param saveFeedbackFrom 举报信息
     */
    @Override
    public void saveReport(SaveFeedbackFrom saveFeedbackFrom) {
        log.debug("保存举报请求,入参:{}", saveFeedbackFrom);
        Feedback feedback = new Feedback();
        BeanUtils.copyProperties(saveFeedbackFrom, feedback);
        if (feedback.getId()!=null){
            feedback.setStatus("已处理");
            feedbackMapper.update(feedback);
        }else{
            feedback.setCreateTime(new Date());
            feedbackMapper.insert(feedback);
        }
    }

    /**
     * 根据id查询举报信息
     * @param id 举报id
     * @return 举报信息
     */
    @Override
    public FeedbackVO selectById(Long id) {
        log.debug("查询举报详情请求,入参:{}", id);
        FeedbackVO feedback = feedbackMapper.selectById(id);
        log.debug("查询举报详情请求,入参:{},出参:{}", id, feedback);
        return feedback;
    }

    /**
     * 查询举报列表
     * @param feedbackQuery 查询条件
     * @return 举报列表
     */
    @Override
    public List<FeedbackVO> select(FeedbackQuery feedbackQuery) {
        log.debug("查询举报列表请求,入参:{}", feedbackQuery);
        List<FeedbackVO> list = feedbackMapper.select(feedbackQuery);
        log.debug("查询举报列表请求,入参:{},出参:{}", feedbackQuery, list);
        return list;
    }

    /**
     * 删除举报信息
     * @param id 举报id
     */
    @Override
    public void delete(Long id) {
        log.debug("删除举报请求,入参:{}", id);
        feedbackMapper.delete(id);
    }
}
